package com.cet.qz.unit01.chapter1_3;

import edu.princeton.cs.algs4.StdIn;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-04-01 22:04
 **/
public class Qz1_3_5 {

    public static void convertToBinary(int num) {
        Stack<Integer> stack = new Stack<>();
        while (num != 0) {
            stack.push(num % 2);
            num /= 2;
        }
        System.out.println("转换为二进制为：");
        for (Integer i : stack) {
            System.out.println(i);
        }
    }

    public static void main(String[] args) {
        System.out.println("请输入一个十进制整数：");
        convertToBinary(StdIn.readInt());
    }
}
